<?php

function changeQueryString () {
  $args   = func_get_args();
  $n_args = func_num_args();
  $out = $_GET;
  for ($i=0; $i < $n_args; $i=$i+2) {
    $out[$args[$i]] = $args[$i+1];
  }
  foreach ($out as $k=>$v) {
    if ($v) {
      $qry .= ($qry == "") ? "?" : "&amp;";
      $qry .= urlencode ($k) . "=" . urlencode ($v);
    }
  }
  return ($qry=="") ? "?" : $qry;
}

function send_mail ($to, $from, $subject, $message) {
	$headers  = "MIME-Version: 1.0\r\n"; 
	$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
	$headers .= "From: ". $from ."\r\n";
	
	$content = "<html><body>". $message ."</body></html>";
	
	return @mail($to, $subject, $content, $headers);
}

function getimageinfo($image,$r_value) {
	list($width, $height, $type, $attr) = getimagesize($image);
	return $$r_value;
}

function this_dir () {
  return basename(dirname($_SERVER['PHP_SELF']));
}

function this_page() {
  return basename($_SERVER['PHP_SELF']);
}

function listDir ($directory) {
  $dir_array = array();
  if ($dir = @opendir( $directory )) { 
    while (($file = readdir($dir)) !== false) {
      if ($file != "." && $file != "..") {
        $dir_array[] = $file;
      }
    }   
    closedir($dir);
  }
  natcasesort($dir_array);
  reset  ($dir_array);
  return $dir_array;
}

function download_file($filename,$filepath) {
	header('Content-type: octet/stream');
	header('Content-Disposition: attachment; filename="'. $filename .'"');
  print file_get_contents($filepath);
}

function nl2li($s) {
	$a = explode("\n",$s);
	foreach ($a as $v) $out .= "<li>". trim($v) ."</li>\n";
	return $out;
}

if (!function_exists('file_get_contents')) {
	function file_get_contents($filename) {
		$handle = fopen($filename, "r");
		$out = fread($handle, filesize($filename));
		fclose($handle);
		return $out;
	}
}

if (!function_exists('array_fill')) {
	function array_fill($iStart, $iLen, $vValue) {
		$aResult = array();
		for ($iCount = $iStart; $iCount < $iLen + $iStart; $iCount++) {
			$aResult[$iCount] = $vValue;
		}
		return $aResult;
	}
}

?>